package com.gallsoft.games.bennyadv;

import com.gallsoft.games.framework.Music;
import com.gallsoft.games.framework.Sound;
import com.gallsoft.games.framework.gamedev2d.Animation;
import com.gallsoft.games.framework.gl.Font;
import com.gallsoft.games.framework.gl.Texture;
import com.gallsoft.games.framework.gl.TextureRegion;
import com.gallsoft.games.framework.impl.GLGame;

public class Assets {
    public static Texture titlescreen;
    public static Texture background;
    public static Texture background2;
    public static Texture background3;
    public static Texture background4;
    public static TextureRegion titlescreenRegion;
    public static TextureRegion backgroundRegion;
    public static TextureRegion backgroundRegion2;
    public static TextureRegion backgroundRegion3;
    public static TextureRegion backgroundRegion4;
    public static TextureRegion debug_box_red_region;
    public static TextureRegion debug_box_blue_region;
    
    public static TextureRegion title;
    public static TextureRegion start;
    public static TextureRegion scoreString;
    public static TextureRegion timeString;
    public static TextureRegion levelString;
    
    public static Texture items; 
    
    public static TextureRegion mainMenu;
    public static TextureRegion platformBlock1;
    public static TextureRegion platformBlock2;
    public static TextureRegion platformBlock3;
    public static TextureRegion platformBlock4;
    //public static TextureRegion platformBlock5;
    //public static TextureRegion platformBlock6;
    public static TextureRegion platformBlock7;
    //public static TextureRegion platformBlock8;
    public static TextureRegion platformBlock9;
    public static TextureRegion platformBlock10;
    public static TextureRegion platformBlock11;
    public static TextureRegion platformBlock12;
    public static TextureRegion platformBlock13;
    public static TextureRegion platformBlock14;
    public static TextureRegion platformBlock15;
    public static TextureRegion platformBlock16;
    public static TextureRegion solidBlock4;
    
    public static TextureRegion movingPlatform1;
    public static TextureRegion movingPlatform2;
    public static TextureRegion movingPlatform3;
    public static TextureRegion movingPlatform4;

    public static TextureRegion ladderBlock1;
    
    public static TextureRegion solidBlock1;
    public static TextureRegion solidBlock2;
    public static TextureRegion solidBlock3;
    
    public static TextureRegion strawberry;
    public static TextureRegion burger;
    public static TextureRegion jellybean;
    
    public static TextureRegion yellowSwitch;
    public static TextureRegion redSwitch;
    public static TextureRegion greenSwitch;
    public static TextureRegion redDoor;
    public static TextureRegion redKey;
    public static TextureRegion orangeDoor;
    public static TextureRegion orangeKey;
    public static TextureRegion greenDoor;
    public static TextureRegion greenKey;
    public static TextureRegion yellowDoor;
    public static TextureRegion yellowKey;
    public static TextureRegion pinkDoor;
    public static TextureRegion pinkKey;
    public static TextureRegion spike1;
    
    public static TextureRegion grass;
    public static TextureRegion stem1;
    public static TextureRegion whiteFlower;
    public static TextureRegion ketchup;
    
    public static TextureRegion wood_exit;
    public static TextureRegion kennel;

    public static TextureRegion livesIcon;
    
    public static TextureRegion button;
    public static TextureRegion arrow;
    public static TextureRegion arrowup;
    public static TextureRegion messageBackground;
    
    public static Animation bennyWalk;
    public static Animation bennyClimb;
    public static Animation bennyDie;
    public static Animation fly;
    public static Animation snail;
    public static Animation crab;
    public static Animation egg;
    public static Animation pinkSweet;
    public static Animation blueSweet;
    public static Animation tomato;

    public static Font font;       
    public static Sound clickSound;
    public static Sound jumpSound;
    public static Sound hitSound;
    public static Sound coinSound;
     
    private static boolean isLoaded = false;

    
    public static void load(GLGame game) {
        // Load textures
        titlescreen = new Texture(game, "titlescreen.png");

        background = new Texture(game, "background.png");
        background2 = new Texture(game, "background2.png");
        background3 = new Texture(game, "background3.png");
        background4 = new Texture(game, "background4.png");
        items = new Texture(game, "sprites2.png"); 

        // Extract backgrounds
        titlescreenRegion = new TextureRegion(titlescreen, 0, 0, 480, 320);
        //backgroundRegion = new TextureRegion(background, 0, 0, 480, 320);
        backgroundRegion = new TextureRegion(background, 0, 0, 480, 512);
        //backgroundRegion2 = new TextureRegion(background2, 0, 0, 480, 320);
        backgroundRegion2 = new TextureRegion(background2, 0, 0, 480, 512);
        backgroundRegion3 = new TextureRegion(background3, 0, 0, 480, 320);
        backgroundRegion4 = new TextureRegion(background4, 0, 0, 480, 512);

        title = new TextureRegion(background, 0, 320, 410, 100);
        start = new TextureRegion(background, 0, 423, 240, 40);
       
        // Extract game graphics
        //debug_box_red_region = new TextureRegion(items, 256, 0, 16, 16);
        //debug_box_blue_region = new TextureRegion(items, 272, 0, 16, 16);
        
        scoreString = new TextureRegion(items, 192, 256, 96, 32);
        timeString = new TextureRegion(items, 288, 256, 64, 32);
        levelString = new TextureRegion(items, 352, 256, 96, 32);
        
        mainMenu = new TextureRegion(items, 0, 360, 300, 110);
        strawberry = new TextureRegion(items, 0, 32, 32, 32);
        burger = new TextureRegion(items, 32, 32, 32, 32);
        jellybean = new TextureRegion(items, 64, 32, 32, 32);

        yellowSwitch = new TextureRegion(items, 448, 0, 32, 32);
        redSwitch = new TextureRegion(items, 448, 32, 32, 32);
        greenSwitch = new TextureRegion(items, 448, 64, 32, 32);
        redDoor = new TextureRegion(items, 448, 192, 32, 32);
        redKey = new TextureRegion(items, 480, 192, 32, 32);
        orangeDoor = new TextureRegion(items, 448, 224, 32, 32);
        orangeKey = new TextureRegion(items, 480, 224, 32, 32);
        greenDoor = new TextureRegion(items, 448, 256, 32, 32);
        greenKey = new TextureRegion(items, 480, 256, 32, 32);
        yellowDoor = new TextureRegion(items, 448, 288, 32, 32);
        yellowKey = new TextureRegion(items, 480, 288, 32, 32);
        pinkDoor = new TextureRegion(items, 448, 320, 32, 32);
        pinkKey = new TextureRegion(items, 480, 320, 32, 32);
        spike1 = new TextureRegion(items, 416, 32, 32, 32);
        
        livesIcon = new TextureRegion(items, 256, 128, 64, 32);

        platformBlock1 = new TextureRegion(items, 0, 0, 32, 32);    // Grass left end
        platformBlock2 = new TextureRegion(items, 32, 0, 32, 32);   // Grass middle
        platformBlock3 = new TextureRegion(items, 64, 0, 32, 32);  // Grass right end
        platformBlock4 = new TextureRegion(items, 192, 0, 32, 32);  // Grey brick
        platformBlock7 = new TextureRegion(items, 96, 0, 32, 32);  // Grass/ground
        
        platformBlock9 = new TextureRegion(items, 256, 0, 32, 32);  // Blue girder
        
        platformBlock10 = new TextureRegion(items, 288, 0, 32, 32);  // Multi-coloured angles
        platformBlock11 = new TextureRegion(items, 352, 0, 32, 32);  // Orange allsort
        platformBlock12 = new TextureRegion(items, 384, 0, 32, 32);  // Yellow allsort
        platformBlock13 = new TextureRegion(items, 416, 0, 32, 32);  // Pink allsort
        platformBlock14 = new TextureRegion(items, 480, 0, 32, 32);  // Orange allsort end
        platformBlock15 = new TextureRegion(items, 480, 32, 32, 32);  // Yellow allsort end
        platformBlock16 = new TextureRegion(items, 480, 64, 32, 32);  // Pink allsort end
        
        movingPlatform1 = new TextureRegion(items, 320, 288, 64, 32);  // Brown allsort (thinner)
        movingPlatform2 = new TextureRegion(items, 192, 288, 64, 32);  // Earthy (thinner)
        movingPlatform3 = new TextureRegion(items, 256, 288, 64, 32);  // Blue tile (thinner)
        movingPlatform4 = new TextureRegion(items, 384, 288, 64, 32);  // Grey brick tile (thinner)
        
        ladderBlock1 = new TextureRegion(items, 320, 0, 32, 32);
        
        solidBlock1 = new TextureRegion(items, 128, 0, 32, 32);
        solidBlock2 = new TextureRegion(items, 480, 96, 32, 32);  // Licorice
        solidBlock3 = new TextureRegion(items, 64, 0, 32, 32);  // Blue tile
        solidBlock4 = new TextureRegion(items, 160, 0, 32, 32);  // Stripey sweet
        
        grass = new TextureRegion(items, 288, 32, 32, 32);
        stem1 = new TextureRegion(items, 160, 32, 32, 32);
        whiteFlower = new TextureRegion(items, 224, 32, 32, 32);
        ketchup = new TextureRegion(items, 384, 32, 32, 32);

        wood_exit = new TextureRegion(items, 320, 64, 64, 64);
        kennel = new TextureRegion(items, 384, 64, 64, 64);
        
        button = new TextureRegion(items, 0, 448, 64, 64);
        arrow = new TextureRegion(items, 64, 448, 64, 64);
        arrowup = new TextureRegion(items, 128, 448, 64, 64);
        messageBackground = new TextureRegion(items, 384, 320, 64, 64);
        //post = new TextureRegion(items, 96, 32, 32, 32);
        
        font = new Font(items, 192, 384, 16, 16, 20);

        
        bennyWalk = new Animation(0.2f,                                 
                new TextureRegion(items, 0, 64, 64, 64),
                new TextureRegion(items, 64, 64, 64, 64),
                new TextureRegion(items, 128, 64, 64, 64),
                new TextureRegion(items, 64, 64, 64, 64),
                new TextureRegion(items, 0, 64, 64, 64),
                new TextureRegion(items, 192, 64, 64, 64),
                new TextureRegion(items, 256, 64, 64, 64),
                new TextureRegion(items, 192, 64, 64, 64));

        bennyDie = new Animation(0.2f,                                 
                new TextureRegion(items, 256, 128, 64, 64),
                new TextureRegion(items, 320, 128, 64, 64));

        bennyClimb = new Animation(0.2f,                                 
                new TextureRegion(items, 384, 128, 64, 64),
                new TextureRegion(items, 448, 128, 64, 64));

        fly = new Animation(0.05f,                                 
                new TextureRegion(items, 0, 128, 64, 64),
                new TextureRegion(items, 64, 128, 64, 64),
                new TextureRegion(items, 128, 128, 64, 64),
                new TextureRegion(items, 192, 128, 64, 64),
                new TextureRegion(items, 64, 128, 64, 64));

        snail = new Animation(0.2f,                                 
                new TextureRegion(items, 0, 192, 64, 64),
                new TextureRegion(items, 64, 192, 64, 64),
                new TextureRegion(items, 128, 192, 64, 64),
                new TextureRegion(items, 192, 192, 64, 64));

        crab = new Animation(0.2f,                                 
                new TextureRegion(items, 0, 256, 64, 64),
                new TextureRegion(items, 64, 256, 64, 64),
                new TextureRegion(items, 128, 256, 64, 64),
                new TextureRegion(items, 64, 256, 64, 64));

        egg = new Animation(0.2f,                                 
                new TextureRegion(items, 256, 192, 64, 64),
                new TextureRegion(items, 320, 192, 64, 64),
                new TextureRegion(items, 384, 192, 64, 64),
                new TextureRegion(items, 320, 192, 64, 64));

        pinkSweet = new Animation(0.2f,                                 
                new TextureRegion(items, 0, 384, 64, 64),
                new TextureRegion(items, 64, 384, 64, 64),
                new TextureRegion(items, 128, 384, 64, 64),
                new TextureRegion(items, 64, 384, 64, 64));

        blueSweet = new Animation(0.2f,                                 
                new TextureRegion(items, 0, 320, 64, 64),
                new TextureRegion(items, 64, 320, 64, 64),
                new TextureRegion(items, 128, 320, 64, 64),
                new TextureRegion(items, 64, 320, 64, 64));

        tomato = new Animation(0.2f,                                 
                new TextureRegion(items, 192, 320, 64, 64),
                new TextureRegion(items, 256, 320, 64, 64),
                new TextureRegion(items, 320, 320, 64, 64),
                new TextureRegion(items, 256, 320, 64, 64));

        //font = new Font(items, 224, 0, 16, 16, 20);
        
        clickSound = game.getAudio().newSound("click.ogg"); 
        coinSound = game.getAudio().newSound("coin.ogg"); 
        hitSound = game.getAudio().newSound("hit.ogg"); 
        jumpSound = game.getAudio().newSound("jump.ogg"); 
        isLoaded = true;
    }       
    
    public static void reload() {
        background.reload();
        background2.reload();
        background3.reload();
        items.reload();
        
        //if (Settings.soundEnabled)
        //    music.play();
    }
    
    public static void playSound(Sound sound) {
        if (Settings.soundEnabled)
            sound.play(1);
    }
    
    public static boolean isLoaded() {
        return isLoaded;
    }
}
